package com.zbkj.service.user.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.common.model.user.UserBankCard;
import com.zbkj.common.request.UserBankCardBindRequest;
import com.zbkj.service.dao.UserBankCardDao;
import com.zbkj.service.user.UserBankCardService;
import org.springframework.stereotype.Service;


/**
* @author keNan
* @description UserBankCardServiceImpl 接口实现
* @date 2025-06-26
*/
@Service
public class UserBankCardServiceImpl extends ServiceImpl<UserBankCardDao, UserBankCard> implements UserBankCardService {

    public void userBindBankCard(UserBankCardBindRequest request, Integer uid) {
        UserBankCard userBankCard = getByUid(uid);
        if (ObjUtil.isNotEmpty(userBankCard)) {
            BeanUtil.copyProperties(request, userBankCard);
            super.updateById(userBankCard);
        } else {
            userBankCard = new UserBankCard();
            BeanUtil.copyProperties(request, userBankCard);
            userBankCard.setUid(uid);
            super.save(userBankCard);
        }
    }

    public UserBankCard getByUid(Integer uid) {
        return super.lambdaQuery().eq(UserBankCard::getUid, uid).one();
    }
}

